package com.lcx.plugin.neteaseCloud.component.handle;

import cn.hutool.core.io.FileUtil;
import com.alibaba.fastjson.JSON;
import com.lcx.plugin.neteaseCloud.music.DataCenter;

import java.io.File;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Objects;

/**
 * @author daxiong
 * @date 2021/10/21 上午9:19
 */
public class UserHandle {

    public static File userFile;

    static {
        String userHome = System.getProperty("user.home");
        userFile = new File(userHome + "/MusicPlugin/user.txt");
    }

    public static void write2Local() {
        // 写入文件
        if (Objects.nonNull(DataCenter.uid)) {
            Map<String, Object> stringObjectMap = DataCenter.transfer2Map();
            String content = JSON.toJSONString(stringObjectMap);
            FileUtil.writeBytes(content.getBytes(StandardCharsets.UTF_8), userFile);
        }
    }

    public static void deleteLocalFile() {
        userFile.delete();
    }
}
